package com.example.administrator.pms.Like;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.administrator.pms.R;
import com.example.administrator.pms.bean.MySQLiteHelper;
import com.example.administrator.pms.bean.Picture;
import com.example.administrator.pms.dao.PictureCollectDao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/4/21.
 */

public class LikeFragment extends Fragment {

    ArrayList fileNames = null;

    public MySQLiteHelper helper;

    @Bind(R.id.show_like_list)
    ListView show_like_list;




    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        PictureCollectDao pictureCollectDao=new PictureCollectDao(getActivity());

        fileNames = new ArrayList();

        View view = inflater.inflate(R.layout.fragment_like, null);
        ButterKnife.bind(this, view);

        List<Map<String, Object>> listItems = new ArrayList<>();

        List<Picture> pictures = new ArrayList<>();
            pictures=pictureCollectDao.findPicture();
//        Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM " + tableName, null);
//        while(cursor.moveToNext()){
//            String name = cursor.getString(cursor.getColumnIndex("_name"));
//            String url = cursor.getString(cursor.getColumnIndex("_url"));
//            Picture picture=new Picture(name,url);
//            pictures.add(picture);
//        }

        for (int i = 0; i < pictures.size(); i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("name",pictures.get(i).name);
            map.put("image", pictures.get(i).url);
            listItems.add(map);
        }
        //设置adapter
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), listItems,
                R.layout.base_line, new String[]{"name", "image"}, new int[]{R.id.name, R.id.list_image});

        show_like_list.setAdapter(adapter);


        return view;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


}
